﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace PClusterModel.Comparer
{
    public class BitarrayEqualityComparer:IEqualityComparer<BitArray>
    {
        #region IEqualityComparer<BitArray> Members

        public bool Equals(BitArray x, BitArray y)
        {
            int hashOfFirst = this.GetHashCode(x);
            int hashOfSecond = this.GetHashCode(y);
            return hashOfFirst == hashOfSecond;
        }

        public int GetHashCode(BitArray obj)
        {
            int result = 0;

            for (byte i = 0; i < obj.Length; i++)
            {
                if (obj[i])
                    result |= (int)(1 << i);
            }

            return result;
        }

        static BitarrayEqualityComparer instance = new BitarrayEqualityComparer();

        public static BitarrayEqualityComparer Instance
        {
            get
            {
                return instance;
            }
        }
        #endregion
    }
}
